package com.fbs.wowo.util.common;

import com.fbs.wowo.exception.InputVerifyFailedException;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;

public class Validator {
    /**
     * 验证字符串不为空
     * @param str
     * @throws InputVerifyFailedException
     */
    public static void verifyStr(String str) throws InputVerifyFailedException {
        if (!StringUtils.hasText(str))
            throw new InputVerifyFailedException("字符串为空");
    }

    /**
     * 验证对象不为空
     * @param object
     * @throws InputVerifyFailedException
     */
    public static void verifyNon(Object object) throws InputVerifyFailedException {
        if (object == null)
            throw new InputVerifyFailedException("对象为空");
    }

    /**
     * 验证BigDecimal不为负数
     * @param num
     * @throws InputVerifyFailedException
     */
    public static void verifyMinus(BigDecimal num) throws InputVerifyFailedException {
        if (num == null)
            throw new InputVerifyFailedException("对象为空");
        if (num.compareTo(new BigDecimal(0)) < 0)
            throw new InputVerifyFailedException("负值警告");
    }
}
